package supershop.service;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import supershop.dao.IShopcartDao;
import supershop.model.Shopcart;

@Service
public class ShopcartService implements IShopcartService {

	@Resource
	private IShopcartDao shopcartDao;
	@Override
	public int addCart(Shopcart cart) {
		//先判断购物车中是否存在该商品
		Shopcart c = shopcartDao.exist(cart.getUid(), cart.getPid());
		if(c!=null) {
			return shopcartDao.addCartNum(c.getId(), cart.getNum());
		}else {
			return shopcartDao.addCart(cart);
		}
	}

}
